#pragma once

#include "Protocol.hpp"
#include <memory>
class NetCal
{
public:
    NetCal() {}
    ~NetCal() {}

    std::shared_ptr<Response> Calculator(std::shared_ptr<Request> req)
    {
        auto resp = Factory::BuildResponseDefault();
        switch (req->GetOper())
        {
        case '+':
            resp->_result = req->GetX() + req->GetY();
            break;
        case '-':
            resp->_result = req->GetX() - req->GetY();
            break;
        case '*':
            resp->_result = req->GetX() * req->GetY();
            break;
        case '/':
        {
            if (req->GetY() == 0)
            {
                resp->_code = 1;
                resp->_desc = "div zero";
            }
            else
            {
                resp->_result = req->GetX() / req->GetY();
            }
        }
        break;
        case '%':
        {
            if (req->GetY() == 0)
            {
                resp->_code = 2;
                resp->_desc = "mod zero";
            }
            else
            {
                resp->_result = req->GetX() % req->GetY();
            }
        }
        break;
        default:
        {
            resp->_code = 3;
            resp->_desc = "illegal opereation";
        }
        break;
        }
        return resp;
    }
};